<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set conditions for automatic caching</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysqlnd-qc-set-cache-condition" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqlnd_qc_set_cache_condition</h1>
  <p class="verinfo">(PECL mysqlnd_qc &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">mysqlnd_qc_set_cache_condition</span> &mdash; <span class="dc-title">Set conditions for automatic caching</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysqlnd-qc-set-cache-condition-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   
   <span class="methodname"><strong>mysqlnd_qc_set_cache_condition</strong></span>
    ( <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$condition_type</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$condition</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$condition_option</code>
   </span>
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Sets a condition for automatic caching of statements which do not contain
   the necessary SQL hints to enable caching of them.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysqlnd-qc-set-cache-condition-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>

     <code class="parameter">condition_type</code>
    </dt>

    <dd>

     <p class="para">
      Type of the condition. The only allowed value is
      <strong><code>MYSQLND_QC_CONDITION_META_SCHEMA_PATTERN</code></strong>.
     </p>
    </dd>

   
   
    <dt>

     <code class="parameter">condition</code>
    </dt>

    <dd>

     <p class="para">
      Parameter for the condition set with <em>condition_type</em>.
      Parameter type and structure depend on <em>condition_type</em>
     </p>
     <p class="para">
      If <em>condition_type</em> equals
      <em>MYSQLND_QC_CONDITION_META_SCHEMA_PATTERN</em>
      <em>condition</em> must be a string. The string sets a pattern.
      Statements are cached if table and database meta data entry of their result sets
      match the pattern. The pattern is checked for a match with the
      <em>db</em> and <em>org_table</em> meta data entries
      provided by the underlying MySQL client server library. Please, check
      the MySQL Reference manual for details about the two entries. The
      <em>db</em> and <em>org_table</em> values are
      concatenated with a dot (<em>.</em>) before matched
      against <em>condition</em>. Pattern matching supports
      the wildcards <em>%</em> and <em>_</em>.
      The wildcard <em>%</em> will match one or many arbitrary
      characters. <em>_</em> will match one arbitrary character.
      The escape symbol is backslash.
     </p>
    </dd>

   
   
    <dt>

     <code class="parameter">condition_option</code>
    </dt>

    <dd>

     <p class="para">
      Option for <em>condition</em>. Type and structure depend
      on <em>condition_type</em>.
     </p>
     <p class="para">
      If <em>condition_type</em> equals
      <em>MYSQLND_QC_CONDITION_META_SCHEMA_PATTERN</em>
      <em>condition_options</em> is the TTL to be used.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 examples" id="refsect1-function.mysqlnd-qc-set-cache-condition-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2299">
   <p><strong>Example #1 <span class="function"><strong>mysqlnd_qc_set_cache_condition()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Cache&nbsp;all&nbsp;accesses&nbsp;to&nbsp;tables&nbsp;with&nbsp;the&nbsp;name&nbsp;"new%"&nbsp;in&nbsp;schema/database&nbsp;"db_example"&nbsp;for&nbsp;1&nbsp;second&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">mysqlnd_qc_set_cache_condition</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLND_QC_CONDITION_META_SCHEMA_PATTERN</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"db_example.new%"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;die(</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;set&nbsp;cache&nbsp;condition!"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"db_example"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"port"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;cached&nbsp;although&nbsp;no&nbsp;SQL&nbsp;hint&nbsp;given&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;title&nbsp;FROM&nbsp;news"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$pdo_mysql&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysql:host=host;dbname=db_example;port=port"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;not&nbsp;cached:&nbsp;no&nbsp;SQL&nbsp;hint,&nbsp;no&nbsp;pattern&nbsp;match&nbsp;*/<br /></span><span style="color: #0000BB">$pdo_mysql</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;title&nbsp;FROM&nbsp;latest_news"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;cached:&nbsp;TTL&nbsp;1&nbsp;second,&nbsp;pattern&nbsp;match&nbsp;*/<br /></span><span style="color: #0000BB">$pdo_mysql</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;title&nbsp;FROM&nbsp;news"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysqlnd-qc-set-cache-condition-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns TRUE on success or FALSE on FAILURE.
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysqlnd-qc-set-cache-condition-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <a href="mysqlnd_qc.pattern_based_caching.html" class="link">Quickstart: pattern based caching</a>
    </li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>